package com.anycl.design.behavioral.observer;

import java.util.ArrayList;
import java.util.List;

/**
 * 具体主题（发布者）
 */
public class ConcreteSubject implements Subject {

    private List<Observer> list = new ArrayList<>();

    @Override
    public void attach(Observer o) {
        list.add(o);
    }

    @Override
    public void detach(Observer o) {
        list.remove(o);
    }

    @Override
    public void notifyObservers() {
        for (Observer o: list)
            o.update();
    }
}
